#region ---Au3Recorder generated code Start ---
Opt("WinWaitDelay", 100)
Opt("WinDetectHiddenText", 1)
Opt("MouseCoordMode", 0)

;Made for Chrome - no bookmarks bar
;125% Screen resolution

$ClickSpeed = 1
$BuffSpeed = 5

$BuffTime = 0.5

$BuffTimeMS = $BuffTime * 60 * 60 * 1000

$SleepTime = 581000
$DelayTime = 5000

$SleptForBuff = 10000000
$SleptForTrade = 0

$MouseMoveSleep = 250
$MouseClickSleep = 10

$TimeoutTime = 1

$FirstBuff = True

; Static Variables for Type selection
$OneOne0 = 796
$OneOne1 = 500

$Delta0 = 79
$Delta1 = 38

$HW0 = 1
$HW1 = 1

$HWP0 = 2
$HWP1 = 1

$Coin0 = 3
$Coin1 = 2

$Horse0 = 2
$Horse1 = 3

$Bow0 = 1
$Bow1 = 3

$Fish0 = 4
$Fish1 = 1

$Water0 = 5
$Water1 = 1

$Bread0 = 4
$Bread1 = 2

$EW0 = 1
$EW1 = 1

$EWP0 = 2
$EWP1 = 1

$Granite0 = 2
$Granite1 = 2

$Xbow0 = 1
$Xbow1 = 3

$BronzeSword0 = 5
$BronzeSword1 = 2

$Cannon0 = 2
$Cannon1 = 3

$Egg0 = 5
$Egg1 = 1

$MapFrag0 = 1
$MapFrag1 = 2
;-----------------------------------------------------------------------------------------------

; Button Statics
$AddOffer0 = 293
$AddOffer1 = 862

$DeliverSelect0 = 803
$DeliverSelect1 = 658

$ReceiveSelect0 = 1142
$ReceiveSelect1 = $DeliverSelect1

$Trade0 = 974
$Trade1 = 587

$TradeTab0 = 134
$TradeTab1 = 911

$OK0 = 1082
$OK1 = 721

$BasicTab0 = 803
$BasicTab1 = 649

$IntermediateTab0 = 920
$IntermediateTab1 = $BasicTab1

$AdvancedTab0 = 1028
$AdvancedTab1 = $BasicTab1

$ExpertTab0 = 1139
$ExpertTab1 = $BasicTab1

$InboxClose0 = 1241
$InboxClose1 = 374

$TraderClose0 = 1293
$TraderClose1 = 329

$GuildClose0 = 1242
$GuildClose1 = 305

$DailyBonusClose0 = 970 ;needs reset
$DailyBonusClose1 = 688

$ClickNewQuest0 = 199
$ClickNewQuest1 = 212

$QuestClose0 = 1232
$QuestClose1 = 335

$MoveFromPos0 = 160 ;unused
$MoveFromPos1 = 79

$MoveToPos0 = 1559 ;unused
$MoveToPos1 = 911

$TipOfTheDayOK0 = 970
$TipOfTheDayOK1 = 715

$AcceptTrade0 = 934
$AcceptTrade1 = 728

$PlusOne0 = 1019
$PlusOne1 = 731

$MinusOne0 = 821
$MinusOne1 = $PlusOne1

$StarMenu0 = 968
$StarMenu1 = 887

$BuffMenu0 = 971
$BuffMenu1 = 838

$FirstBuff0 = 814
$FirstBuff1 = 644

$SecondBuff0 = 868
$SecondBuff1 = 644

$BuffFromPos0 = 622
$BuffFromPos1 = 233

$BuffToPos0 = 1291
$BuffToPos1 = $BuffFromPos1

$CancelBuff0 = 962
$CancelBuff1 = 125

$BackToIsland0 = 615
$BackToIsland1 = 1015

$KeepBuffing = True

$PHBuffAdd0 = 1233
$PHBuffAdd1 = 633

$PHBuffOK0 = 1107
$PHBuffOK1 = 667

;-----------------------------------------------------------------------------------------------
; Exotic Sawmill Buffs
$ExoticSawmillOne0 = 936
$ExoticSawmillOne1 = 447

$ExoticSawmillTwo0 = 820
$ExoticSawmillTwo1 = 519

$ExoticSawmillThree0 = 878
$ExoticSawmillThree1 = 629

$ExoticSawmillFour0 = 1053
$ExoticSawmillFour1 = 663

$ExoticSawmillFive0 = 1171
$ExoticSawmillFive1 = 593

$ExoticSawmillSix0 = 1113
$ExoticSawmillSix1 = 483

$ESBuffOne = True
$ESBuffTwo = True
$ESBuffThree = True
$ESBuffFour = True
$ESBuffFive = True
$ESBuffSix = True

$BuffColor = 0x04cf20

$BuffCheckPos0 = 1779
$BuffCheckPos1 = 618

$BuffTimePerBuilding = 1150

;-----------------------------------------------------------------------------------------------

; Number Statics
$One0 = 835
$One1 = 732 ;725 before

$Two0 = 848
$Two1 = $One1

$Five0 = 849
$Five1 = $One1

$Ten0 = 851
$Ten1 = $One1

$Thirteen0 = 852
$Thirteen1 = $One1

$Sixteen0 = 853
$Sixteen1 = $One1

$TwentyFour0 = 856
$TwentyFour1 = $One1

$TwentySeven0 = 857
$TwentySeven1 = $One1

$Thirty0 = 858
$Thirty1 = $One1

$ThirtyEight0 = 861 ;True Lock
$ThirtyEight1 = $One1

$FortyOne0 = 862
$FortyOne1 = $One1

$FortyFour0 = 863 ;True lock
$FortyFour1 = $One1

$FortySix0 = 864
$FortySix1 = $One1

$FortyNine0 = 865 ;856 before
$FortyNine1 = $One1

$FiftyTwo0 = 866
$FiftyTwo1 = $One1

$NinetyNine0 = 883
$NinetyNine1 = $One1

$OneHundredTwentyOne0 = 891
$OneHundredTwentyOne1 = $One1

$OneHundredTwentyNine0 = 894
$OneHundredTwentyNine1 = $One1

$OneHundredThirtyFour0 = 896
$OneHundredThrityFour1 = $One1

$OneHundredFiftyOne0 = 902
$OneHundredFiftyOne1 = $One1

$TwoHundredOne0 = 920
$TwoHundredOne1 = $One1

$TwoHundredTwentyFive0 = 929
$TwoHundredTwentyFive1 = $One1

$TwoHundredFifty0 = 938
$TwoHundredFifty1 = $One1

$ThreeHundred0 = 956
$ThreeHundred1 = $One1

$FourHundred0 = 1002
$FourHundred1 = $One1
;------------------------------------------------------------------------------------------------

#cs
	Type1	5 coin for 400 HW
	Type2	400 HWP for 27coin
	Type3	10 coin for 400 HWP
	Type4	400 HWP for 400 Horse
	Type5	200 HWP for 400 Bows
#ce

Enum $Type1 = 0, $Type2, $Type3, $Type4, $Type5, $Type6, $Type7, $Type8, $Type9, $Type10, $Type11, $TypeMax

; ^ is CTRL, ! is ALT

HotKeySet("^{ENTER}", "end")
HotKeySet("^{`}", "SetRandom")
HotKeySet("^{1}", "SetType1")
HotKeySet("^{2}", "SetType2")
HotKeySet("^{3}", "SetType3")
HotKeySet("^{4}", "SetType4")
HotKeySet("^{5}", "SetType5")
HotKeySet("^{6}", "SetType6")

HotKeySet("!{1}", "SetType7")
HotKeySet("!{2}", "SetType8")
HotKeySet("!{3}", "SetType9")
HotKeySet("!{4}", "SetType10")
HotKeySet("!{5}", "SetType11")

HotKeySet("!{`}", "CreateBuff")

HotKeySet("!{7}", "TestPosition")

HotKeySet("^{END}", "StopBuffing")
HotKeySet("^{7}", "BuffExoticSawmills")

HotKeySet("^{=}", "Accept")

HotKeySet("!{Z}", "BackToIsland")

HotKeySet("!{F3}", "CheckExoticSawmills")
HotKeySet("^{8}", "NightStockup")
HotKeySet("^{9}", "Here")
HotKeySet("^{0}", "NotHere")

;HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d


$random = 1;
$MousePosX = MouseGetPos(0)
$MousePosY = MouseGetPos(1)

$WindowHandle = "TEMP"

$GetRandom = True

$Stockup = False

$DragCounter = 0

$Here = False

Sleep(2000)

Beep()

While True

	If $GetRandom Then

		$random = Random(0, 100, 1)

		If $Stockup == False Then

			Select
				Case $random >= 0 And $random <= 70
					$random = $Type2

				Case $random > 70 And $random <= 87
					$random = $Type3

				Case $random > 87 And $random <= 97
					$random = $Type1

				Case $random > 97 And $random <= 99
					$random = $Type4

				Case $random > 99 And $random <= 100
					$random = $Type5

			EndSelect

		Else

			Select

				Case $random > 0 And $random <= 75
					$random = $Type3

				Case $random > 75 And $random <= 100
					$random = $Type1

			EndSelect

		EndIf


	EndIf

	$WindowHandle = WinGetHandle("[ACTIVE]")

	If Not WinActive("The Settlers Online - Zeus [Realm 1] - Google Chrome", "") Then WinActivate("The Settlers Online - Zeus [Realm 1] - Google Chrome", "")
	;WinWaitActive("The Settlers Online - Zeus [Realm 1] - Google Chrome","")

	$DragCounter = 0;

	Do
		MouseMove($MoveFromPos0, $MoveFromPos1, $ClickSpeed)
		MouseDown("left")
		MouseMove($MoveToPos0, $MoveToPos1, $ClickSpeed)
		MouseUp("left")
		$DragCounter += 1
	Until $DragCounter == 3

	MouseWheel("up", 5)

	BackToIsland()

	Sleep(3000)

	Send("3")

	; Close Open Windows
	MouseClick("left", $ClickNewQuest0, $ClickNewQuest1, $ClickSpeed)
	MouseClick("left", $QuestClose0, $QuestClose1, $ClickSpeed)

	MouseClick("left", $DailyBonusClose0, $DailyBonusClose1, $ClickSpeed)
	MouseClick("left", $InboxClose0, $InboxClose1, $ClickSpeed)
	MouseClick("left", $TraderClose0, $TraderClose1, $ClickSpeed)
	MouseClick("left", $GuildClose0, $GuildClose1, $ClickSpeed)

	; Trade Tab
	MouseClick("left", $TradeTab0, $TradeTab1, $ClickSpeed)

	; Add Offer
	MouseClick("left", $AddOffer0, $AddOffer1, $ClickSpeed)

	; Deliver Select
	MouseClick("left", $DeliverSelect0, $DeliverSelect1, $ClickSpeed)

	;Case Statement
	Select

		Case $random == $Type1
			;------------------ Type 1  3 coin for 400 HW -----------------------
			MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Coin0 - 1) * $Delta0), $OneOne1 + (($Coin1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $Two0, $Two1, $ClickSpeed)

			MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)
			;-------------------------------------------------------------------

		Case $random == $Type2
			;------------------ Type 2 400 HWP for 24 coin -----------------------
			MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($HWP0 - 1) * $Delta0), $OneOne1 + (($HWP1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
			;-------------------------------------------------------------------

		Case $random == $Type3
			#cs
				;------------------ Type 3 10 coin for 400 HWP -----------------------
				MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

				MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

				MouseClick("left", $Ten0, $Ten1, $ClickSpeed)
				;-------------------------------------------------------------------
			#ce

			;------------------ Type 3 150 coin for 400 EWL -----------------------
			MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Coin0 - 1) * $Delta0), $OneOne1 + (($Coin1 - 1) * $Delta1), $ClickSpeed)

			;MouseClick("left", $OneHundredFiftyOne0, $OneHundredFiftyOne1, $ClickSpeed)

			;MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)

			MouseClick("left", $OneHundredThirtyFour0, $OneHundredThrityFour1, $ClickSpeed)

			MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)

			;-------------------------------------------------------------------

		Case $random == $Type4
			#cs
				;------------------ Type 4 400 HWP for 400 Horse -----------------------
				MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

				MouseClick("left", $OneOne0+(($HWP0-1)*$Delta0), $OneOne1+(($HWP1-1)*$Delta1), $ClickSpeed)

				MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
				;-------------------------------------------------------------------
			#ce

			;------------------ Type 3 400 EWP for 225 Coin -----------------------
			MouseClick("left", $ExpertTab0, $ExpertTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($EWP0 - 1) * $Delta0), $OneOne1 + (($EWP1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
			;-------------------------------------------------------------------

		Case $random == $Type5
			#cs
				;------------------ Type 5 200 HWP for 400 Bows -----------------------
				MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

				MouseClick("left", $OneOne0+(($HWP0-1)*$Delta0), $OneOne1+(($HWP1-1)*$Delta1), $ClickSpeed)

				MouseClick("left", $TwoHundredOne0, $TwoHundredOne1, $ClickSpeed)
				;-------------------------------------------------------------------

			#ce

			;------------------ Type 3 5 coin for 400 Bread -----------------------
			MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Coin0 - 1) * $Delta0), $OneOne1 + (($Coin1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $Five0, $Five1, $ClickSpeed)
			;-------------------------------------------------------------------

		Case $random == $Type6
			;------------------ Type 6 400 Water for 400 Fish -----------------------
			MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Water0 - 1) * $Delta0), $OneOne1 + (($Water1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
			;-------------------------------------------------------------------

		Case $random == $Type7
			;------------------ Type 7 27 coin for 50 Granite -----------------------
			MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Coin0 - 1) * $Delta0), $OneOne1 + (($Coin1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $TwentySeven0, $TwentySeven1, $ClickSpeed)
			;-------------------------------------------------------------------

		Case $random == $Type8
			;------------------ Type 8 400 coin for 200 xbow -----------------------
			MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Coin0 - 1) * $Delta0), $OneOne1 + (($Coin1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
			;-------------------------------------------------------------------

		Case $random == $Type9

			;------------------ Type 9 400 Bread for 400 Bronze Swords

			MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Bread0 - 1) * $Delta0), $OneOne1 + (($Bread1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)

		Case $random == $Type10

			;----------------- Type 10 50 cannons for 350 coins ----------------
			MouseClick("left", $ExpertTab0, $ExpertTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Cannon0 - 1) * $Delta0), $OneOne1 + (($Cannon1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FortyNine0, $FortyNine1, $ClickSpeed)

			MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)
			;--------------------------------------------------------------------

		Case $random == $Type11

			;------------------ Type 11 400 Bread for 3 Map Fragments -----------------------
			MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Bread0 - 1) * $Delta0), $OneOne1 + (($Bread1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
			;-------------------------------------------------------------------

			;MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)

	EndSelect

	; Select OK Button
	MouseClick("left", $OK0, $OK1, $ClickSpeed)

	$ThisHWND = WinGetHandle("[ACTIVE]")

	; Receive Select
	MouseClick("left", $ReceiveSelect0, $ReceiveSelect1, $ClickSpeed)

	;Case Statement
	Select

		Case $random == $Type1
			;------------------ Type 1  5coin for 400 HW -----------------------
			MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($HW0 - 1) * $Delta0), $OneOne1 + (($HW1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
			;-------------------------------------------------------------------

		Case $random == $Type2
			;------------------ Type 2 400 HWP for 27coin  -----------------------
			MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Coin0 - 1) * $Delta0), $OneOne1 + (($Coin1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $TwentyFour0, $TwentyFour1, $ClickSpeed)
			;-------------------------------------------------------------------

			;MouseClick("left", $Thirteen0, $Thirteen1, $ClickSpeed)

		Case $random == $Type3

			#cs
				;------------------ Type 3 10 coin for 400 HWP -----------------------
				MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

				MouseClick("left", $OneOne0+(($HWP0-1)*$Delta0), $OneOne1+(($HWP1-1)*$Delta1), $ClickSpeed)

				MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
				;-------------------------------------------------------------------
			#ce

			MouseClick("left", $ExpertTab0, $ExpertTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($EW0 - 1) * $Delta0), $OneOne1 + (($EW1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)

		Case $random == $Type4

			#cs
				;------------------ Type 4 400 HWP for 400 Horse -----------------------
				MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

				MouseClick("left", $OneOne0+(($Horse0-1)*$Delta0), $OneOne1+(($Horse1-1)*$Delta1), $ClickSpeed)

				MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
				;-------------------------------------------------------------------
			#ce

			MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Coin0 - 1) * $Delta0), $OneOne1 + (($Coin1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $TwoHundredOne0, $TwoHundredOne1, $ClickSpeed)

			MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)

		Case $random == $Type5

			#cs
				;------------------ Type 5 200 HWP for 400 Bows -----------------------
				MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

				MouseClick("left", $OneOne0+(($Bow0-1)*$Delta0), $OneOne1+(($Bow1-1)*$Delta1), $ClickSpeed)

				MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
				;-------------------------------------------------------------------

			#ce

			MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Bread0 - 1) * $Delta0), $OneOne1 + (($Bread1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)

		Case $random == $Type6
			;------------------ Type 5 200 HWP for 400 Bows -----------------------
			MouseClick("left", $BasicTab0, $BasicTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Fish0 - 1) * $Delta0), $OneOne1 + (($Fish1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
			;-------------------------------------------------------------------

		Case $random == $Type7

			;----------------- Type 7 27 coin for 49 Granite --------------------
			MouseClick("left", $ExpertTab0, $ExpertTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Granite0 - 1) * $Delta0), $OneOne1 + (($Granite1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FortyNine0, $FortyNine1, $ClickSpeed)
			;-------------------------------------------------------------------

			MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)

		Case $random == $Type8

			;----------------- Type 8 400 coin for 200 Map Frags --------------------
			MouseClick("left", $BasicTab0, $BasicTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($MapFrag0 - 1) * $Delta0), $OneOne1 + (($MapFrag1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $TwoHundredOne0, $TwoHundredOne1, $ClickSpeed)
			;-------------------------------------------------------------------

			MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)

		Case $random == $Type9

			MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($BronzeSword0 - 1) * $Delta0), $OneOne1 + (($BronzeSword1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)

		Case $random == $Type10

			;------------------ Type 10 50 cannon for 350 coin -----------------------
			MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($Coin0 - 1) * $Delta0), $OneOne1 + (($Coin1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
			;-------------------------------------------------------------------

		Case $random == $Type11

			;------------------ Type 11 400 Bread for 3 Map Fragments  -----------------------
			MouseClick("left", $BasicTab0, $BasicTab1, $ClickSpeed)

			MouseClick("left", $OneOne0 + (($MapFrag0 - 1) * $Delta0), $OneOne1 + (($MapFrag1 - 1) * $Delta1), $ClickSpeed)

			MouseClick("left", $Two0, $Two1, $ClickSpeed)

			MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)

	EndSelect

	; Select OK Button
	MouseClick("left", $OK0, $OK1, $ClickSpeed)


	; Send Trade
	MouseClick("left", $Trade0, $Trade1, $ClickSpeed)

	Sleep(50)

	MouseClick("left", $Trade0, $Trade1, $ClickSpeed)

	;Send("3")


	;------------------------- Return to last window ----------------------------------------------

	If $Here Then
		MouseMove($MousePosX, $MousePosY, $ClickSpeed)

		; Activate last known Window and move mouse back to where it was
		WinActivate($WindowHandle)
		;WinWaitActive($WindowHandle,"")
	EndIf

	#cs

		$SleptForTrade = 0
		$SleptForBuff += 12000

		Do

		If $SleptForBuff>=$BuffTimeMS Then
		BuffExoticSawmills()
		$SleptForTrade
		EndIf

		Sleep(1000)

		$SleptForTrade += 1000
		$SleptForBuff += 1000

		Until $SleptForTrade>=$SleepTime

	#ce


	;BuffExoticSawmills()
	Sleep($BuffTimePerBuilding * 6)

	Sleep($SleepTime - $DelayTime)

	Beep(400)

	Sleep($DelayTime)

	Beep()

WEnd

; Functions -----------------------------------------------------------------------------

Func SetType1()
	$GetRandom = False
	$random = $Type1

	MsgBox(0, "SetType1", "3 coin for 400 Hardwood", $TimeoutTime)
EndFunc   ;==>SetType1

Func SetType2()
	$GetRandom = False
	$random = $Type2

	MsgBox(0, "SetType2", "400 Hardwood Planks for 24 coin", $TimeoutTime)
EndFunc   ;==>SetType2

Func SetType3()
	$GetRandom = False
	$random = $Type3

	;MsgBox(0, "SetType3", "11 coin for 400 Hardwood Planks", $TimeoutTime)
	MsgBox(0, "SetType3", "150 coin for 400 Exotic Wood Logs", $TimeoutTime)
EndFunc   ;==>SetType3

Func SetType4()
	$GetRandom = False
	$random = $Type4

	;MsgBox(0, "SetType4", "400 Hardwood Planks for 400 Horses", $TimeoutTime)
	MsgBox(0, "SetType4", "400 Exotic Wood Planks for 225 coin", $TimeoutTime)
EndFunc   ;==>SetType4

Func SetType5()
	$GetRandom = False
	$random = $Type5

	;MsgBox(0, "SetType5", "200 Hardwood Planks for 400 Bows", $TimeoutTime)
	MsgBox(0, "SetType5", "5 coin for 400 bread", $TimeoutTime)
EndFunc   ;==>SetType5

Func SetType6()
	$GetRandom = False
	$random = $Type6

	MsgBox(0, "SetType6", "400 Water for 400 Fish", $TimeoutTime)
EndFunc   ;==>SetType6

Func SetType7()
	$GetRandom = False
	$random = $Type7

	MsgBox(0, "SetType7", "27 coin for 50 Granite", $TimeoutTime)
EndFunc   ;==>SetType7

Func SetType8()
	$GetRandom = False
	$random = $Type8

	MsgBox(0, "SetType8", "400 Coins for 200 Map Fragments", $TimeoutTime)
EndFunc   ;==>SetType8

Func SetType9()
	$GetRandom = False
	$random = $Type9

	MsgBox(0, "SetType9", "400 Bread for 400 Bronze Sword", $TimeoutTime)
EndFunc   ;==>SetType9

Func SetType10()
	$GetRandom = False
	$random = $Type10

	MsgBox(0, "SetType10", "50 cannons for 400 coin", $TimeoutTime)
EndFunc   ;==>SetType10

Func SetType11()
	$GetRandom = False
	$random = $Type11

	MsgBox(0, "SetType11", "400 Bread for 3 Map Fragments", $TimeoutTime)
EndFunc   ;==>SetType11

Func SetRandom()
	$GetRandom = True

	MsgBox(0, "SetRandom", "Random", $TimeoutTime)
EndFunc   ;==>SetRandom

Func NightStockup()
	If $Stockup == False Then
		MsgBox(0, "SetNightTimeStockup", "On", $TimeoutTime)
		$Stockup = True
	Else
		MsgBox(0, "SetNightTimeStockup", "Off", $TimeoutTime)
		$Stockup = False
	EndIf

EndFunc   ;==>NightStockup

Func Here()
	$Here = True
	MsgBox(0, "Here", "HERE!", $TimeoutTime)
EndFunc   ;==>Here

Func NotHere()
	$Here = False
	MsgBox(0, "Not Here", "BE GONE!", $TimeoutTime)
EndFunc   ;==>NotHere

Func Accept()
	$TempMousePos0 = MouseGetPos(0)
	$TempMousePos1 = MouseGetPos(1)

	MouseClick("left", $TempMousePos0, $TempMousePos1, $ClickSpeed)

	MouseClick("left", $AcceptTrade0, $AcceptTrade1, $ClickSpeed)

	MouseMove($TempMousePos0, $TempMousePos1, $ClickSpeed)
EndFunc   ;==>Accept

Func BackToIsland()

	MouseClick("left", $BackToIsland0, $BackToIsland1, $ClickSpeed)
	MouseMove($BackToIsland0, 839, $ClickSpeed)

EndFunc   ;==>BackToIsland

Func TestPosition()

	;MouseClick("left", $PHBuffAdd0, $PHBuffAdd1, $ClickSpeed)

	;CheckExoticSawmills()

	;MouseClick("left", $Forty0, $Forty1, $ClickSpeed)

	BackToIsland()

EndFunc   ;==>TestPosition

Func CreateBuff()

	$MousePosX = MouseGetPos(0)
	$MousePosY = MouseGetPos(1)

	MouseClick("left")

	MouseClick("left", $PHBuffAdd0, $PHBuffAdd1, $ClickSpeed)
	MouseClick("left", $PHBuffAdd0, $PHBuffAdd1, $ClickSpeed)
	MouseClick("left", $PHBuffAdd0, $PHBuffAdd1, $ClickSpeed)

	MouseClick("left", $PHBuffOK0, $PHBuffOK1, $ClickSpeed)

	MouseMove($MousePosX, $MousePosY, $ClickSpeed)

EndFunc   ;==>CreateBuff

Func CheckExoticSawmills()

	AutoItSetOption("PixelCoordMode", 0)

	$ClickCheckDelay = 150

	MouseClick("left", $ExoticSawmillOne0, $ExoticSawmillOne1, $ClickSpeed)
	Sleep(250)
	Local $var = PixelGetColor($BuffCheckPos0, $BuffCheckPos1)

	If $var == $BuffColor Then
		$ESBuffOne = False
		;MsgBox(0, "Color", "FALSE -- $var = " & hex($var) & " " & "Buff Color = " & hex($BuffColor), 500, $ThisHWND)
	Else
		$ESBuffOne = True
		;MsgBox(0, "Color", "TRUE -- $var = " & hex($var) & " " & "Buff Color = " & hex($BuffColor), 500, $ThisHWND)
	EndIf


	MouseClick("left", $ExoticSawmillTwo0, $ExoticSawmillTwo1, $ClickSpeed)
	Sleep($ClickCheckDelay)
	$var = PixelGetColor($BuffCheckPos0, $BuffCheckPos1)

	If $var == $BuffColor Then
		$ESBuffTwo = False
	Else
		$ESBuffTwo = True
	EndIf


	MouseClick("left", $ExoticSawmillThree0, $ExoticSawmillThree1, $ClickSpeed)
	Sleep($ClickCheckDelay)
	$var = PixelGetColor($BuffCheckPos0, $BuffCheckPos1)

	If $var == $BuffColor Then
		$ESBuffThree = False
	Else
		$ESBuffThree = True
	EndIf


	MouseClick("left", $ExoticSawmillFour0, $ExoticSawmillFour1, $ClickSpeed)
	Sleep($ClickCheckDelay)
	$var = PixelGetColor($BuffCheckPos0, $BuffCheckPos1)

	If $var == $BuffColor Then
		$ESBuffFour = False
	Else
		$ESBuffFour = True
	EndIf


	MouseClick("left", $ExoticSawmillFive0, $ExoticSawmillFive1, $ClickSpeed)
	Sleep($ClickCheckDelay)
	$var = PixelGetColor($BuffCheckPos0, $BuffCheckPos1)

	If $var == $BuffColor Then
		$ESBuffFive = False
	Else
		$ESBuffFive = True
	EndIf


	MouseClick("left", $ExoticSawmillSix0, $ExoticSawmillSix1, $ClickSpeed)
	Sleep($ClickCheckDelay)
	$var = PixelGetColor($BuffCheckPos0, $BuffCheckPos1)

	If $var == $BuffColor Then
		$ESBuffSix = False
	Else
		$ESBuffSix = True
	EndIf

	#cs
		Local $coord = PixelSearch(1769, 722, 1802, 752, 0x04cf20, 15, $ThisHWND)
		If Not @error Then
		MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1], 500, $ThisHWND)
		EndIf

	#ce

	;MsgBox(0, "The hex color is", Hex($var, 6),2)

EndFunc   ;==>CheckExoticSawmills

Func BuffExoticSawmills()

	$KeepBuffing = True

	Send("0")
	Sleep(150)
	Send("3")

	MouseWheel("up", 10)

	MouseMove($BuffFromPos0, $BuffFromPos1, $BuffSpeed)
	MouseDown("left")
	MouseMove($BuffToPos0, $BuffToPos1, $BuffSpeed)
	MouseUp("left")

	CheckExoticSawmills()

	;---------------- Level 2 ------------------------------------
	If $ESBuffOne == True Then
		If $KeepBuffing == True Then
			FirstBuff()
			MouseMove($ExoticSawmillOne0, $ExoticSawmillOne1, $BuffSpeed)
			Sleep($MouseMoveSleep)
			MouseDown("left")
			Sleep($MouseClickSleep)
			MouseUp("left")
			CancelBuff()
		EndIf
	EndIf

	If $ESBuffTwo == True Then
		If $KeepBuffing == True Then
			FirstBuff()
			MouseMove($ExoticSawmillTwo0, $ExoticSawmillTwo1, $BuffSpeed)
			Sleep($MouseMoveSleep)
			MouseDown("left")
			Sleep($MouseClickSleep)
			MouseUp("left")
			CancelBuff()
		EndIf
	EndIf

	If $ESBuffThree == True Then
		If $KeepBuffing == True Then
			FirstBuff()
			MouseMove($ExoticSawmillThree0, $ExoticSawmillThree1, $BuffSpeed + 5)
			Sleep($MouseMoveSleep)
			MouseDown("left")
			Sleep($MouseClickSleep)
			MouseUp("left")
			CancelBuff()
		EndIf
	EndIf

	If $ESBuffFour == True Then
		If $KeepBuffing == True Then
			FirstBuff()
			MouseMove($ExoticSawmillFour0, $ExoticSawmillFour1, $BuffSpeed)
			Sleep($MouseMoveSleep)
			MouseDown("left")
			Sleep($MouseClickSleep)
			MouseUp("left")
			CancelBuff()
		EndIf
	EndIf

	If $ESBuffFive == True Then
		If $KeepBuffing == True Then
			FirstBuff()
			MouseMove($ExoticSawmillFive0, $ExoticSawmillFive1, $BuffSpeed)
			Sleep($MouseMoveSleep)
			MouseDown("left")
			Sleep($MouseClickSleep)
			MouseUp("left")
			CancelBuff()
		EndIf
	EndIf

	If $ESBuffSix == True Then
		If $KeepBuffing == True Then
			FirstBuff()
			MouseMove($ExoticSawmillSix0, $ExoticSawmillSix1, $BuffSpeed)
			Sleep($MouseMoveSleep)
			MouseDown("left")
			Sleep($MouseClickSleep)
			MouseUp("left")
			CancelBuff()
		EndIf
	EndIf

	$SleptForBuff = (6 * $BuffTimePerBuilding) - (Int($ESBuffOne) * $BuffTimePerBuilding) - (Int($ESBuffTwo) * $BuffTimePerBuilding) - (Int($ESBuffThree) * $BuffTimePerBuilding) - (Int($ESBuffFour) * $BuffTimePerBuilding) - (Int($ESBuffFive) * $BuffTimePerBuilding) - (Int($ESBuffSix) * $BuffTimePerBuilding)

	Sleep($SleptForBuff)

EndFunc   ;==>BuffExoticSawmills

Func FirstBuff()

	MouseClick("left", $StarMenu0, $StarMenu1, $ClickSpeed)
	MouseClick("left", $BuffMenu0, $BuffMenu1, $ClickSpeed)

	If $FirstBuff == True Then
		MouseClick("left", $FirstBuff0, $FirstBuff1, $ClickSpeed)
		$FirstBuff = False
	Else
		MouseClick("left", $SecondBuff0, $SecondBuff1, $ClickSpeed)
		$FirstBuff = True
	EndIf

EndFunc   ;==>FirstBuff

Func CancelBuff()

	MouseClick("left", $CancelBuff0, $CancelBuff1, $ClickSpeed)

EndFunc   ;==>CancelBuff

Func StopBuffing()

	$KeepBuffing = False

EndFunc   ;==>StopBuffing

;-----------------------------------------------------------------------------------------------------

Func end()
	Exit
EndFunc   ;==>end

Func _WinWaitActivate($title, $text, $timeout = 0)
	WinWait($title, $text, $timeout)
	If Not WinActive($title, $text) Then WinActivate($title, $text)
	WinWaitActive($title, $text, $timeout)
EndFunc   ;==>_WinWaitActivate

;End --------------------------------------------------------------------------------------------------
